import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  const MyApp() : super();
  @override
  State<StatefulWidget> createState() {
    return new _ParentWidgetState();
  }
}

class _ParentWidgetState extends State<MyApp> {
  bool active = false;

  void _handleTapBoxChange(bool newValue) {
    setState(() {
      active = newValue;
    });
  }

  void _selectedTap(bool newValue) {
    setState(() {
      active = newValue;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new BoxTap(
      active: active,
      onChange: _handleTapBoxChange,
      boxSelected: _selectedTap,
    );
  }
}

class BoxTap extends StatelessWidget {
  BoxTap({Key key, this.active, this.onChange, this.boxSelected})
      : super(key: key);
  final bool active;
  ValueChanged<bool> onChange;
  ValueChanged<bool> boxSelected;

  void _tapHandle() {
    onChange(!active);
  }

  void _boxTap() {
    boxSelected(!active);
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('状态'),
        ),
        body: new Center(
          child: new Column(
            children: <Widget>[
              new GestureDetector(
                child: new Container(
                  width: double.infinity,
                  height: 200,
                  color: active == false ? Colors.red : Colors.blue,
                  child: new Image(
                    image: AssetImage(active == false
                        ? 'assets/images/food05.jpeg'
                        : 'assets/images/food01.jpeg'),
                  ),
                ),
                onTap: _tapHandle,
              ),
              new Image.network(
                active == false
                    ? 'http://wx3.sinaimg.cn/mw690/5eef6257gy1g4k3yvkr51g208c08cx6p.gif'
                    : 'https://p.upyun.com/demo/webp/webp/animated-gif-0.webp',
                fit: BoxFit.fitHeight,
                width: 200,
                height: 300,
              ),
              new FlatButton(
                child: new Text(
                  'onpen route',
                  style: TextStyle(fontSize: 30, color: Colors.blue),
                ),
                onPressed: () {},
              ),
              new Text(
                '\uE914 \uE000 \uE90D \uE90A',
                style: TextStyle(
                    fontFamily: 'MaterialIcons',
                    fontSize: 30,
                    color: Colors.green),
              ),
              new Icon(Icons.accessible, color: Colors.green, size: 30),
              new Icon(Icons.access_time, color: Colors.green, size: 30),
              new Checkbox(
                value: active,
                activeColor: Colors.blue,
                onChanged: (value) {
                  _boxTap();
                },
              ),
              new Switch(
                value: active,
                onChanged: (value) {
                  _boxTap();
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
